home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 896 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: vandevod@cs.rpi.edu (David Vandevoorde)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: "explicit" default constructor?
  5. Date: 28 Mar 1996 16:28:41 GMT
  6. Organization: RPI Computer Science
  7. Sender: vandevod@avs.cs.rpi.edu
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <xso4tr99osk.fsf@avs.cs.rpi.edu>
  10. References: <31588662.F1@cs.tu-berlin.de> <4jbqog$78i@engnews1.Eng.Sun.COM>
  11.     <315A5C7A.6AF5@cs.tu-berlin.de>
  12. NNTP-Posting-Host: taumet.eng.sun.com
  13. X-Nntp-Posting-Host: avs.cs.rpi.edu
  14. In-Reply-To: Roman Lechtchinsky's message of 28 Mar 96 09:38:43 GMT
  15. X-Newsreader: Gnus v5.1
  16. Content-Length: 1042
  17. X-Lines: 34
  18. Originator: clamage@taumet
  19.  
  20. >>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
  21. [...]
  22. >> If a constructor's parameters all have default values, it can be a
  23. >> converting constructor, and declaring it "explicit" prevents it from
  24. >> being invoked implicitly.
  25.  
  26. RL> Yes, I've had this in mind, too. In the following case:
  27.  
  28. RL> class A
  29. RL> {
  30. RL>  explicit A( int x=0 );
  31. RL> };
  32.  
  33. RL> how do you call the default constructor? Can it still be invoked
  34. RL> implicitly and what is the "explicit" syntax if not? IMO, something like
  35.  
  36. RL> A a;
  37.  
  38. RL> is not explicit ( maybe I'm wrong here and this does explicitly call the 
  39. RL> default constructor explicitly - but where does the DWP define it? ). An 
  40. RL> explicit call would rather be
  41.  
  42. Yes: the above is quite ``explicit''. Implicit would be:
  43.  
  44.     a = 23; // Implicitly equivalent to `a = A(23)' if no `explicit'
  45.         // specification (and no preferred int-assignment
  46.         // alternative).
  47.  
  48. RL> A a();
  49.  
  50. This is not a constructor invacation anyway (it's the declaration of
  51. a function `a' returning an object of type `A').
  52.  
  53.     Daveed
  54.  
  55.  
  56. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  57. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  58. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  59. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  60. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  61.